package com.uusee.crawler.pageprocessor.baike.baidu;

import org.apache.oro.text.regex.MatchResult;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.PatternCompiler;
import org.apache.oro.text.regex.PatternMatcher;
import org.apache.oro.text.regex.PatternMatcherInput;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;


public class TiebaCategoryPageProcessor {
	public static void main(String[] args) {
		try {
			//String url = "http://tieba.baidu.com/f?ct=536870912&sn=%CA%B1%C9%D0%D0%DD%CF%D0&bs=%C2%C3%D3%CE&rn=200&cm=1101&tn=simpleCategory&pn=2";
			//String page = Crawler.crawl(url, "gb2312");
			//innerProcess(url,page);
		}catch (Exception e) {
		}
	}
	public static void innerProcess(String url,String pageText) {
		try {
			int c=0;
			PatternCompiler compiler = new Perl5Compiler();
			Pattern pattern = compiler.compile("<td width=\"20%\"><a href=\"/f\\?kw=(.*?)\" target=_blank>(.*?)</a></td>", Perl5Compiler.CASE_INSENSITIVE_MASK);
			PatternMatcher matcher = new Perl5Matcher();
			PatternMatcherInput input = new PatternMatcherInput(pageText);
			while (matcher.contains(input, pattern)) {
				try {
					MatchResult m = matcher.getMatch();
					String text1 = m.group(1);
					String text2 = m.group(2);
					c++;
					System.out.println(text1+"===="+text2);
				}catch (Exception e) {
				}
			}
			System.out.println(c);
		}catch (Exception e) {
		}
	}
}
